/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package conventus;

import java.util.Locale;
import javax.mail.MessagingException;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

/**
 *
 * @author Leonardo
 */
public class Funcoes {
    
    public static void sendEmail( String remetente,String smtp, String usuarioSmtp, String senhaSmtp,String assunto, String para,String CC,String corpo ) throws MessagingException{
            /* Função desenvolvida por Douglas Tybel */
            java.util.Properties p = new java.util.Properties();
            p.put("mail.smtp.auth", "true");
            p.put("mail.smtp.starttls.enable", "true");
            p.put("mail.smtp.host", smtp);
            p.put("mail.smtp.port", "587");
            
            final String user,pwd;
            user = usuarioSmtp;
            pwd  = senhaSmtp;
            
            javax.mail.Authenticator auth = new javax.mail.Authenticator() {

                @Override
                public javax.mail.PasswordAuthentication getPasswordAuthentication() {
                    return new javax.mail.PasswordAuthentication(user, pwd);
                }
            };
            //Enviar email
            javax.mail.Session session = javax.mail.Session.getInstance(p, auth);
            javax.mail.internet.MimeMessage msg = new javax.mail.internet.MimeMessage(session);
            // "de" e "para"
            msg.setFrom(new javax.mail.internet.InternetAddress( remetente  ));
            msg.setRecipient(javax.mail.Message.RecipientType.TO, new javax.mail.internet.InternetAddress(para));
            if (CC.length() > 0)
            msg.setRecipient(javax.mail.Message.RecipientType.CC, new javax.mail.internet.InternetAddress( CC  ));
            
            msg.setSentDate(new java.util.Date());
            msg.setSubject( assunto );
            msg.setText(  corpo  );

            //Enviando mensagem (tentando)
            javax.mail.Transport.send(msg);
            JOptionPane.showMessageDialog(null,"Mensagem Enviada!", "Aviso!",  JOptionPane.WARNING_MESSAGE );
    }
    
}